package jisuanji;

import java.awt.geom.Path2D;
import java.awt.Shape;

public class Trapezoid extends MyShape {
    private double a, b, h;
    
    public Trapezoid(double a, double b, double h) {
        super("梯形");
        this.a = a;
        this.b = b;
        this.h = h;
    }
    
    @Override
    public double getArea() {
        return (a + b) * h / 2.0;
    }
    
    @Override
    public double getPerimeter() {
        double c = Math.abs(b - a) / 2.0;
        double side = Math.sqrt(c * c + h * h);
        return a + b + 2 * side;
    }
    
    @Override
    public Shape getRealShape() {
        Path2D path = new Path2D.Double();
        double offset = Math.abs(b - a) / 2.0;
        path.moveTo(0, 0);
        path.lineTo(b, 0);
        path.lineTo(b - offset, h);
        path.lineTo(offset, h);
        path.closePath();
        return path;
    }
}